package com.loanapp.service;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import com.loanapp.domain.CreditHistoryBean;

/**
 * @author Administrator
 */
public class JmsSenderCreditProcess {

	private JmsTemplate jmsTemplate;

	/**
	 * @return Returns the jmsTemplate.
	 */
	public JmsTemplate getJmsTemplate() {
		return jmsTemplate;
	}

	/**
	 * @param jmsTemplate
	 *            The jmsTemplate to set.
	 */
	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}

	public void sendMessage(final CreditHistoryBean creditHistory) {
		jmsTemplate.send(new MessageCreator() {
			public Message createMessage(Session session) throws JMSException {

				MapMessage mapMessage = session.createMapMessage();
				mapMessage.setLong("loanAppId", creditHistory.getLoanAppId());
				mapMessage
						.setInt("creditScore", creditHistory.getCreditScore());
				mapMessage.setString("creditHistory", creditHistory
						.getCreditHistory());

				return mapMessage;
			}
		});

	}
}
